var service = require('../../utilService.js')
var manager = require('../../favManager.js')
var noti = require('../../WxNotificationCenter.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isLoading: {
      type: Boolean,
      value: true
    },
    anctionType: {
      type: Number,
      value: 0   // 0 竞拍中  1 已经送出
    },
    dataSource: {
      type: [],
      value: null,
      observer: function (newValue, oldValue) {
        this.setData({ items: manager.configProductList(newValue)})
      }
    },
    brand: {
      type: Boolean,
      value: false
    },
    hasNextPage: {
      type: Boolean,
      value: false
    },
    needStatusShow: {
      type: Boolean,
      value: false,
    },// 是否需要显示 右上角  商品 审核状态
  },

  /**
   * 组件的初始数据
   */
  data: {
    //Item类型 1 正常  2 带开奖
    itemType: 1,
    items: [],
    favIds: [],
    favDelIds: [],
  },
  ready: function() {},

  detached: function () {},

  /**
   * 组件的方法列表
   */
  methods: {
    itemClick(e) {
      let data = this.properties.dataSource[1]
      this.triggerEvent("selectedItem", data)
    },
    favClick(data) {
      
    },
    favCallBack(data) {
      var store = data.detail.store
      var id = data.detail.id
      var index = this.data.favIds.indexOf(id)
      var delIndex = this.data.favDelIds.indexOf(id)

      if (store == 0) {  //删除 
        if (index != -1) {
            this.data.favIds.splice(index, 1)
        }
        if (delIndex == -1) {
          this.data.favDelIds.splice(-1, 0, id)
        }
      }else { //添加
        if (index == -1) {
          this.data.favIds.splice(-1, 0, id)
        }
        if (delIndex != -1) {
          this.data.favDelIds.splice(index, 1)
        }
      }
    },
    selectedItem(data) {
      this.triggerEvent("selectedItem", data)
    },
    refreshProductds() {
      console.log('refreshProducts')
    }
  }
})
